package com.ds.lens.data.service.dao.sql.provider;

import com.ds.lens.data.service.dao.entity.LensDatasource;
import org.apache.ibatis.jdbc.SQL;

public class LensDatasourceProvider {

    public String insertSelective(LensDatasource record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("lens_datasource");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=INTEGER}");
        }

        if (record.getSource() != null) {
            sql.VALUES("source", "#{source,jdbcType=VARCHAR}");
        }

        if (record.getDsSchema() != null) {
            sql.VALUES("ds_schema", "#{dsSchema,jdbcType=VARCHAR}");
        }

        if (record.getDsSql() != null) {
            sql.VALUES("ds_sql", "#{dsSql,jdbcType=VARCHAR}");
        }

        if (record.getMetric() != null) {
            sql.VALUES("metric", "#{metric,jdbcType=VARCHAR}");
        }

        if (record.getTags() != null) {
            sql.VALUES("tags", "#{tags,jdbcType=VARCHAR}");
        }

        if (record.getApplicationId() != null) {
            sql.VALUES("application_id", "#{applicationId,jdbcType=BIGINT}");
        }

        if (record.getApplicationKey() != null) {
            sql.VALUES("application_key", "#{applicationKey,jdbcType=VARCHAR}");
        }

        if (record.getCreator() != null) {
            sql.VALUES("creator", "#{creator,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.VALUES("mender", "#{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.VALUES("modified_time", "#{modifiedTime,jdbcType=TIMESTAMP}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(LensDatasource record) {
        SQL sql = new SQL();
        sql.UPDATE("lens_datasource");

        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=BIGINT}");
        }

        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=INTEGER}");
        }

        if (record.getSource() != null) {
            sql.SET("source = #{source,jdbcType=VARCHAR}");
        }

        if (record.getDsSchema() != null) {
            sql.SET("ds_schema = #{dsSchema,jdbcType=VARCHAR}");
        }

        if (record.getDsSql() != null) {
            sql.SET("ds_sql = #{dsSql,jdbcType=VARCHAR}");
        }

        if (record.getMetric() != null) {
            sql.SET("metric = #{metric,jdbcType=VARCHAR}");
        }

        if (record.getTags() != null) {
            sql.SET("tags = #{tags,jdbcType=VARCHAR}");
        }
//
//        if (record.getSchema() != null) {
//            sql.SET("application_id = #{applicationId,jdbcType=BIGINT}");
//        }
//
//        if (record.getSchema() != null) {
//            sql.SET("application_key = #{applicationKey,jdbcType=VARCHAR}");
//        }

        if (record.getMender() != null) {
            sql.SET("mender = #{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.SET("modified_time = #{modifiedTime,jdbcType=TIMESTAMP}");
        }

        sql.WHERE("id = #{id,jdbcType=BIGINT}");

        return sql.toString();
    }
}
